﻿using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using ReflectionStudio.Core.Events;
namespace WPFExcelReport
{
    public partial class TQP12 : ViewBase
    {
        #region ==MERKM===========
        public static readonly DependencyProperty MERKMProperty = DependencyProperty.Register("MERKM",
            typeof(string), typeof(TQP12),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnMERKMChanged));
        public string MERKM
        {
            get
            {
                return (string)GetValue(MERKMProperty);
            }
            set
            {
                SetValue(MERKMProperty, value);
                ((VQPMERKM)MV).MERKM = value;
             }
        }
        private static void OnMERKMChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TQP12;
            if (src != null)
            {
                src.MERKM = (string)e.NewValue;
            }
        }
        #endregion

        #region ==NORM===========
        public static readonly DependencyProperty NORMProperty = DependencyProperty.Register("NORM",
            typeof(string), typeof(TQP12),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnNORMChanged));
        public string NORM
        {
            get
            {
                return (string)GetValue(NORMProperty);
            }
            set
            {
                SetValue(NORMProperty, value);
                ((VQPMERKM)MV).NORM = value;
            }
        }
        private static void OnNORMChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TQP12;
            if (src != null)
            {
                src.NORM = (string)e.NewValue;
            }
        }
        #endregion 

        #region ==dwQP===========
        public static readonly DependencyProperty dwQPProperty = DependencyProperty.Register("dwQP",
            typeof(DataRow), typeof(TQP12),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OdwQPChanged));
        public DataRow dwQP
        {
            get
            {
                return (DataRow)GetValue(dwQPProperty);
            }
            set
            {
                SetValue(dwQPProperty, value);
            }
        }
        private static void OdwQPChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TQP12;
            if (src != null)
            {
                DataRow row = (DataRow)e.NewValue;
                src.dwQP = row;
            }

        }
        #endregion


        public TQP12()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VQPMERKM();
            this.DataContext = MV;
            InitializeComponent();
        }

        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            base.Window_Loaded(sender, e);
        }

        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            dwQP = dwMaster; 
            if (dwQP != null)
            {
                MERKM = dwQP["QPMMERKM"].ToString();
            }
            else
            {
                MERKM = "";
            }
        }

        public override void QueryCommand(object sender, RoutedEventArgs e)
        {
            //GPPARTIE GPGART GPGFARBE GPBEM1 GPBEM2
            DataRow dwData = TBMain.NewRow();
            dwData["QPMMANDANT"] = app.Mandant;
            dwData["QPMMERKM"] = ART; 
            dwData["QPMNORM"] = NORM;
            if (ART.Trim() == "0000")
            {
                dwData["QPMMERKM"] ="";
            }
            dwData["QPMBEZ"] = DES; 
            DataSet SResult = ((VQPMERKM)MV).QueryQPMERKM(dwData, 2);
            MergeData(SResult, true);
        }


    }
}
